﻿<%@ WebHandler Language="C#" Class="SYS_Message_sel" %>

using System;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
using System.Collections.Generic;
using System.Web.SessionState;

public class SYS_Message_sel : IHttpHandler, IRequiresSessionState
{
    sqlhelp sql = new sqlhelp();
    SYS_Messageresult result = new SYS_Messageresult();
    string str = "";
    DataTable dt = new DataTable();
    List<SYS_Message> SYS_CategoryList = new List<SYS_Message>();
    string sort = "createTime";
    string sorttype = "desc";
    
    public void ProcessRequest (HttpContext context) {
        try
        {
            if (context.Session["comid"] == null)
            {
                result.code = "-1";
                result.msg = "用户未登录";
                unit.send(context, result);
                return;
            }
            if (context.Request["pageNo"] == null)
            {
                result.code = "0";
                result.msg = "未传递页码";
                unit.send(context, result);
                return;
            }

            result.code = "1";
            string where = " and Enable = 1 ";

            string Id = "";
            if (context.Request["Id"] != null)
            {
                Id = context.Request["Id"].ToString();
                where = where + " and Id = '" + Id + "'";
            }
            string StoreId = context.Session["comid"].ToString();
            
            where = where + " and StoreId = '" + StoreId + "'";

            string Code = "";
            if (context.Request["Code"] != null)
            {
                Code = context.Request["Code"].ToString();
                where = where + " and Code = '" + Code + "'";
            }
            string Name = "";
            if (context.Request["Name"] != null)
            {
                Name = context.Request["Name"].ToString();
                where = where + " and Name like '%" + Name + "%'";
            }

            int pageIndex = int.Parse(context.Request["pageNo"].ToString());

            dt = sql.GetPermissionsPager(sort, sorttype, pageIndex, 10, where, "SYS_Message").Tables[0];
            //dt = sql.myDataSet("select * from SYS_Category where 1 = 1 " + where).Tables[0];
            result.total = sql.GetCount("SYS_Message", where);
            int len = dt.Rows.Count;
            if (len > 0)
            {
                for (int i = 0; i < len; i++)
                {
                    SYS_Message _SYS_Category = new SYS_Message();
                    _SYS_Category.Id = dt.Rows[i]["Id"].ToString();
                    _SYS_Category.Code = dt.Rows[i]["Code"].ToString();
                    _SYS_Category.StoreId = dt.Rows[i]["StoreId"].ToString();
                    _SYS_Category.UserName = dt.Rows[i]["UserName"].ToString();
                    _SYS_Category.SubStance = dt.Rows[i]["SubStance"].ToString();
                    _SYS_Category.Title = dt.Rows[i]["Title"].ToString();
                    _SYS_Category.Url = dt.Rows[i]["Url"].ToString();
                    _SYS_Category.ImageUrlID = dt.Rows[i]["ImageUrl"].ToString();
                    _SYS_Category.AuditFlg = dt.Rows[i]["AuditFlg"].ToString();
                    _SYS_Category.CreateTime = dt.Rows[i]["CreateTime"].ToString();
                    _SYS_Category.Enable = dt.Rows[i]["Enable"].ToString();
                    //查询动态对应图片
                    _SYS_Category.ImageUrl = unit.getImg(dt.Rows[i]["ImageUrl"].ToString());
                    
                    SYS_CategoryList.Add(_SYS_Category);
                }
                result.data = SYS_CategoryList;
            }

        }
        catch (Exception e1)
        {
            result.code = "0";
            result.msg = e1.Message;
        }
        unit.send(context, result);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

public class SYS_Messageresult : result
{
    public List<SYS_Message> data = new List<SYS_Message>();
    public int total = 0;

}

public class SYS_Message
{
    public string Id = "";
    public string Code = "";
    public string StoreId = "";
    public string UserName = "";
    public string SubStance = "";
    public string Title = "";
    public string Url = "";
    public string ImageUrl = "";
    public string ImageUrlID = "";
    public string AuditFlg = "";
    public string CreateTime = "";
    public string Enable = "";
        
}